package com.itmd.aopAnno;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;


@Component("myaspect")
@Aspect
public class MyAspect {


    @Before("execution(* com.itmd.aopAnno.*.*(..))")
    public void before () {
        System.out.println("前置增强");
    }


    @After("MyAspect.pointcut()")   //第一种方式,添加切点表达式
    public void after() {
        System.out.println("最终后置增强");
    }


    @AfterReturning("pointcut()")  //第二种方式添加切点表达式
    public void afterReturning () {
        System.out.println("后置增强");
    }


    //环绕指的就是 即有前置增强，又有后置增强
    @Around("execution(* com.itmd.aopAnno.*.*(..))")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("环绕前置增强");
        Object o = pjp.proceed();
        System.out.println("环绕后增强");
        return o;
    }

    public void afterThrowing() {
        System.out.println("异常抛出增强");
    }



    //抽取 切点 表达式
    @Pointcut("execution(* com.itmd.aopAnno.*.*(..))")
    public void pointcut() {}

}
